<template>
    <aside class="site-aside-container" v-loading="loading">
        <div class="avatar">
            <Avatar :url="data.avatar" :size="90" />
        </div>
        <h1 class="title">{{ data.siteTitle }}</h1>
        <nav>
            <!-- router-link 全局组件，根据 router 模式，生成对应的 a 标签，会无刷新跳转
            属性 to 是跳转的链接，可以传入一个对象 { name: router 的 name } -->
            <router-link
                v-for="item in items"
                :key="item.name"
                :to="{ name: item.name }"
                :exact="item.exact"
                active-class="active"
                exact-active-class=""
                ><Icon :type="item.icon" />{{ item.text }}
                <!-- exact 是否精准匹配
                active-class  模糊匹配样式名，默认为：router-link-active   
                exact-active-class   精准匹配样式名，默认为：router-link-exact-active -->
            </router-link>
        </nav>
        <div class="contact">
            <a :href="data.github"
                ><Icon type="github" />{{ data.githubName }}</a
            >
            <a><Icon type="mail" />{{ data.mail }}</a>
            <a
                ><Icon type="qq" />{{ data.qq }}
                <div class="pop">
                    <img :src="data.qqQrCode" />
                </div>
            </a>
            <a
                ><Icon type="weixin" />{{ data.weixin }}
                <div class="pop">
                    <img :src="data.weixinQrCode" />
                </div>
            </a>
        </div>
        <div class="icp">{{ data.icp }}</div>
    </aside>
</template>

<script>
import { mapState } from "vuex"
import Avatar from "@/components/Avatar"
import Icon from "@/components/Icon"
// import { get_data } from "@/mixins"

export default {
    // 混入公共代码，之所以是数组，是因为可以混入多个配置代码
    // mixins: [
    //     get_data({
    //         url: "/api/setting",
    //         data_value: { avatar: "" }
    //     })
    // ],
    components: {
        Avatar,
        Icon
    },
    data() {
        return {
            items: [
                {
                    name: "Home",
                    icon: "home",
                    text: "首页",
                    exact: true // 是否精准匹配
                },
                {
                    name: "Blog",
                    icon: "blog",
                    text: "文章",
                    exact: false // 文章不需要精准匹配
                },
                {
                    name: "About",
                    icon: "about",
                    text: "关于我",
                    exact: true
                },
                {
                    // 全局组件 router-link，通过路由的 name，找到对应的路由路径（path）
                    name: "Project",
                    icon: "code",
                    text: "项目&效果",
                    exact: true
                }
            ]
        }
    },
    computed: mapState("setting", ["loading", "data"])
}
</script>

<style lang="less">
.site-aside-container {
    background-color: #202020;
    height: 100%;
    width: 100%;
    padding: 10px;
    // 防止 padding 把容器撑开
    box-sizing: border-box;
    position: relative;
    .avatar {
        margin: 15px 0;
        text-align: center;
    }
    .title {
        font-size: 23px;
        text-align: center;
        color: darkcyan;
        font-family: 华文新魏;
    }
    nav,
    .contact {
        display: flex;
        flex-direction: column;
        a {
            color: #aaa;
            font-size: 12px;
            padding: 8px 0 8px 25px;
            text-align: left;
            &:hover,
            // router-link 的匹配样式   
            &.active {
                color: #fff;
                background-color: #bbb3;
            }
            .iconfont {
                margin-right: 7px;
                vertical-align: middle;
            }
        }
    }
    .contact {
        margin-top: 60px;
        a {
            cursor: pointer;
            padding-left: 0;
            font-size: 11px;
            position: relative;
            .iconfont {
                font-size: 20px;
            }
            &:hover .pop {
                transform: scaleY(1);
            }
            .pop {
                position: absolute;
                bottom: 40px;
                transform: scaleY(0);
                transform-origin: center bottom;
                transition: transform 0.4s;
                img {
                    width: 130px;
                    height: 130px;
                    display: block;
                    border-radius: 10px;
                }
                &::after {
                    content: "";
                    position: absolute;
                    width: 14px;
                    height: 14px;
                    left: 50%;
                    bottom: -7px;
                    transform: translateX(-50%) rotate(45deg);
                    background-color: #fff;
                }
            }
        }
    }
    .icp {
        font-size: 10px;
        color: #888;
        text-align: left;
        position: absolute;
        bottom: 20px;
        cursor: pointer;
        &:hover {
            color: #ccc;
        }
    }
}
</style>
